<?php
/**
 * TaskController.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-04-17 09:15:57
 * @modified    2023-04-17 09:15:57
 *
 */

namespace App\Http\Controllers;

use App\Repositories\TaskRepo;
use Illuminate\Http\Request;

class TaskController extends BaseModuleController
{
    /**
     * @OA\Get(
     *     path="/tasks/types",
     *     tags={"Task"},
     *     summary="获取任务类型",
     *     description="获取任务类型",
     *     operationId="task_types",
     *     security={{"bearerAuth":{}}},
     *     @OA\Response(response=200, description="请求成功"),
     *     @OA\Response(response=401,description="鉴权失败"),
     *     @OA\Response(response=422, description="请求异常")
     * )
     */
    public function types(Request $request)
    {
        try {
            $types = TaskRepo::getTypes();
            return message('获取成功', true, $types);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function index(Request $request)
    {
        try {
            $tasks = TaskRepo::getList();
            return list_message('获取成功', true, $tasks);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function fetch(Request $request, $id)
    {
        try {
            $taskCount = TaskRepo::fetch($id);
            return message('获取成功', true, $taskCount);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function destroy(Request $request, $id)
    {
        try {
            TaskRepo::destroy($id);
            return message('删除成功', true);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function store(Request $request)
    {
        try {
            $taskCount = TaskRepo::store();
            return message('创建成功', true, $taskCount);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function products(Request $request, $id)
    {
        try {
            $products = TaskRepo::products($id);
            return message('获取成功', true, $products);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function start(Request $request, $id)
    {
        try {
            $task = TaskRepo::start($id);
            return message('成功开始任务', true, $task);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function complete(Request $request, $id)
    {
        try {
            $task = TaskRepo::complete($id);
            return message('成功完成任务', true, $task);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function close(Request $request, $id)
    {
        try {
            $task = TaskRepo::close($id);
            return message('成功关闭任务', true, $task);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function update(Request $request, $id)
    {
        try {
            $task = TaskRepo::update($id);
            return message('成功编辑任务', true, $task);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    public function status(Request $request)
    {
        try {
            $status = TaskRepo::status();
            return message('获取成功', true, $status);
        } catch (\Exception $e) {
            return  message($e->getMessage(), false);
        }
    }

    public function list_all()
    {
        try {
            $data = TaskRepo::listAll();
            return list_message('获取成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }
}